"""
--------------------------------------------------------
@File             : EdgeGateCommuChannel.py
@Creat Time       : 2021-01-21
@Author           : wangzp
@Site             :
@Software         : PyCharm
@file Conent      :
--------------------------------------------------------
@Revise history   :
@Version          : V12
@Amendant records :
     1)wangzp  2021-01-21
"""

import EdgeGateData
import time

# 用于接收消息，参数：(ID，socket对象，ip和端口号的元组)
def MsgResv(id,AcceptSocket,addr):
    while True:
        # 判断连接状态
        if(EdgeGateData.gConnectedStateDictionary[addr] == 0):
            break
        time.sleep(2)
        try:
            # 接收信息
            recvData = AcceptSocket.recv(1024)
            print("来自{0},接收到到数据为{1}".format(addr,recvData.decode("utf-8")))
            # 存储接收到的数据
            EdgeGateData.gSocketRevDataList.append(recvData)
        except Exception as e:
            print("接收线程：接收失败，{0}连接以断开，{1}".format(addr,e))
            # 重置连接状态为断开（0）
            EdgeGateData.gConnectedStateDictionary[addr] = 0
            AcceptSocket.close()
            pass